import { instance } from './index'

interface IUserquery {
  query?: any
  pagenum?: number
  pagesize?: number
}

interface IUserstate {
  uId: number
  type: boolean
}

interface IAdduser {
  username: string
  password: string
  email?: string
  mobile?: string
}

interface IEdituser {
  email: string
  mobile: string
}
export const userList = (params: IUserquery): any => {
  return instance.request({
    url: '/users',
    params
  })
}

export const changeuserstate = (info: IUserstate) => {
  return instance.request({
    method: 'put',
    url: `/users/${info.uId}/state/${info.type}`
  })
}

export const adduser = (info: IAdduser) => {
  return instance.request({
    url: '/users',
    method: 'post',
    data: info
  })
}

export const edituser = (id: number, info: IEdituser): any => {
  return instance.request({
    url: '/users/' + id,
    method: 'put',
    data: info
  })
}

export const deleteuser = (id: number) => {
  return instance.request({
    url: '/users/' + id,
    method: 'delete'
  })
}
